package com.sywb.chuangyebao.library.player;

import org.bining.footstone.utils.SharedUtils;

/**
 * 播放器工具类
 */
public class PlayerUtils {

    public static final String USETRAFFICPLAY = "UseTrafficPlay";

    /**
     * 设置是否可以使用移动网络播放
     */
    public static void setUseTrafficPlay(boolean isUseTrafficPlay) {
        SharedUtils.put(USETRAFFICPLAY, isUseTrafficPlay);
    }

    /**
     * 获取是否可以使用移动网络播放
     */
    public static boolean getUseTrafficPlay() {
        return SharedUtils.getBoolean(USETRAFFICPLAY, false);
    }

    /**
     * 格式化时间（毫秒）
     */
    public static String formatTime(int ms) {
        int totalSeconds = ms / 1000;
        int seconds = totalSeconds % 60;
        int minutes = totalSeconds / 60 % 60;
        int hours = totalSeconds / 60 / 60;
        String timeStr = "";
        if (hours > 9) {
            timeStr += hours + ":";
        } else if (hours > 0) {
            timeStr += "0" + hours + ":";
        }
        if (minutes > 9) {
            timeStr += minutes + ":";
        } else if (minutes > 0) {
            timeStr += "0" + minutes + ":";
        } else {
            timeStr += "00:";
        }
        if (seconds > 9) {
            timeStr += seconds;
        } else if (seconds > 0) {
            timeStr += "0" + seconds;
        } else {
            timeStr += "00";
        }
        return timeStr;
    }

}
